package com.smart.mattress.account.server.impl;

import com.smart.mattress.account.server.DeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Created by user on 17/3/12.
 */
public class DeviceServiceImpl implements DeviceService{

    Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);

    @Autowired
    RestTemplate restTemplate;

    final String SERVICE_NAME="device";//设备服务名称,在配置文件中配置

    @Override
    public boolean isExist(String no) {


        MultiValueMap<String,Object> requestBody = new LinkedMultiValueMap();
        requestBody.add("no", no);

        boolean result = false;

        try{
            result = restTemplate.postForObject("http://" + SERVICE_NAME +"/message_alarm/add_alarm_message",requestBody,Boolean.class);
        }catch (Exception e){
            logger.error("http error",e);
        }

        return result;
    }
}
